/*
 * accept.c
 *
 *  Created on: 2009-5-28
 *      Author: root
 */
#include <sys/types.h>
#include <unistd.h>


int accept(int sockfd,const struct sockaddr *myaddr,int *addrlen){
	sockmsg retmsg;
	int rv;
#ifndef EASY_ACCEPT
	msg message;
	memset(&message,0,sizeof(msg));
	message.mtype=MSG_USR_ACCEPT;
	message.pid=getpid();
	message.sock=sockfd;
	if((rv=msgsnd(tcpipstackid,&message,sizeof(msg)-sizeof(long),IPC_NOWAIT))<0){
		fprintf(stderr,"tcp/ip stack does not work!\n");
		return -1;
	}
#endif
	if((rv=msgrcv(processqid,&retmsg,sizeof(sockmsg)-sizeof(long),0,0))<0){
		fprintf(stderr,"tcp/ip stack does not work!\n");
		return -1;
	}
	*myaddr=retmsg.sock_addr;
	*addrlen=sizeof(retmsg.sock_addr);
	return retmsg.ret;
}
